package com.bjpowernode;

import com.bjpowernode.domain.Student;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;


public class MyApp {
    public static void main(String[] args) throws IOException {
        String config = "mybatis.xml";
        InputStream in = Resources.getResourceAsStream(config);
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        SqlSessionFactory factory = builder.build(in);
        SqlSession sqlSession = factory.openSession();

        String sqlId = "com.bjpowernode.dao.StudentDao.insertStudent";
        //List<Student> studentList = sqlSession.selectList(sqlId);
        Student student = new Student();
        student.setId(6);
        student.setName("黄杰");
        student.setEmail("11@qq.com");
        student.setAge(2);
        int nums = sqlSession.insert(sqlId,student);

        sqlSession.commit();
        System.out.println(nums == 1 ? "插入成功!":"插入失败！");


        sqlSession.close();
    }
}
